// 停车场
class Car {
    constructor(number) {
        this.number = number;
    }
}

class Camera {
    shot(car) {
        return {
            num: car.number,
            inTime: Date.now()
        }
    }
}

class Screen {
    show(car, inTime) {
        console.log('车牌号', car.number);
        console.log('停车时间', Date.now() - inTime)
    }
}

class Park {
    constructor(floors) {
        this.floors = floors;
        this.carList = {};
        this.screen = new Screen();
        this.camera = new Camera();
    }
    entry(car) {
        // 通过摄像头获取信息
        const info = this.camera.shot(car)
        // 停到某个停车位
        const i = Number.parseInt(Math.random() * 100 % 100);
        const place = this.floors[0].place[i]
        place.entry();
        info.place = place;
        this.carList[car.number] = info;
    }
    out(car) {
        const info = this.carList[car.number];
        // 将停车位清空
        const place = info.place;
        place.out();
        this.screen.show(car, info.inTime);
        delete this.carList[car.number];
    }
    emptyNum() {
        return this.floors.map(floor => {
            return `${floot.index}层还有${floor.emptyPlaceNum()}个车位`
        }).join('\n');
    }
}

// 层
class Floor {
    constructor(index, places) {
        this.index = index;
        this.places = places;
    }
    emptyPlaceNum() {
        let num = 0;
        this.places.forEach(p => {
            if (p.empty) {
                num += 1;
            }
        });
        return num;
    }
}

// 车位
class Place {
    constructor() {
        this.empty = true;
    }
    out() {
        this.empty = true;
    }
    entry() {
        this.empty = false;
    }
}